<?php

//cronname:www_csdn123_net_kuaibao

//week:

//day:

//hour:

//minute:0,10,20,30,40,50


if(!defined('IN_DISCUZ')) {

	exit('Access Denied');

}
require './source/plugin/csdn123com_kuaibao/common.fun.php';
if(!isset($_G['cache']['plugin'])){

	loadcache('plugin');

}
$hzw_startcron=$_G['cache']['plugin']['csdn123com_kuaibao']['hzw_startcron'];
$csdn123_cron=DB::fetch_first("SELECT * FROM " . DB::table("csdn123kuaibao_cron") . " ORDER BY catchnum ASC  LIMIT 1");
$csdn123_firt_news=DB::fetch_first("SELECT * FROM " . DB::table("csdn123kuaibao_news") . " WHERE tid=0 and del=0 ORDER BY ID DESC LIMIT 1");
if(empty($csdn123_cron)==false && $hzw_startcron==1 && empty($csdn123_firt_news)==true)
{
	DB::query("UPDATE " . DB::table("csdn123kuaibao_cron") . " SET catchnum=catchnum+1,catchtime=". time() . " WHERE ID=" . dintval($csdn123_cron["ID"]));
	$keyword=$csdn123_cron['keyword'];
	$uidstr=$csdn123_cron['uidstr'];
	$fid=$csdn123_cron['fid'];
	$typeid=$csdn123_cron['typeid'];
	$keyword=diconv($keyword,CHARSET,'UTF-8');
	$dataCatchUrl = kuaibaoKeyword($keyword);
	$htmlcode=dfsockopen($dataCatchUrl);	
	if(strlen($htmlcode)<200)
	{
		$htmlcode=dfsockopen($dataCatchUrl,0,'','',FALSE,'',15,TRUE,'URLENCODE',FALSE);
	}
	$htmlcode=base64_encode($htmlcode);
	$htmlcode=dfsockopen('http://discuz.csdn123.net/catch/kuaibao/now.catch.php',0,array('htmlcode'=>$htmlcode));
	$htmlcode=preg_replace('/^\s+|\s+$/','',$htmlcode);
	$htmlcode=base64_decode($htmlcode);
	$linkArr=dunserialize($htmlcode);
	if(is_array($linkArr)==true && count($linkArr)>0)
	{		

		foreach($linkArr as $linkValue)
		{
			$chk=DB::fetch_first("SELECT ID FROM " . DB::table('csdn123kuaibao_news') . " WHERE fromurl='" . daddslashes($linkValue['href']) . "' LIMIT 1");
			if(empty($chk))
			{

				$linkValue['text']=diconv($linkValue['text'],'UTF-8');
				$insertData=array();
				$insertData['fromurl']=$linkValue['href'];
				$insertData['subject']=$linkValue['text'];
				$insertData['uidstr']=$uidstr;				
				$insertData['fid']=$fid;
				$insertData['typeid']=$typeid;				
				DB::insert('csdn123kuaibao_news',$insertData);

			}			

		}
	}
	
}elseif($hzw_startcron==1 && empty($csdn123_firt_news)==false){
	
	send_thread($csdn123_firt_news['ID']);
	
}

?>